package process_demo.data_share;

/**
 * @author haomin
 * @date 2022/04/20 21:44
 **/
public class Main3 {
    // 进程中只有一个 r，就这一个 r
    static int r = 0;   // 定义为静态属性

    static class MyThread extends Thread {
        @Override
        public void run() {
            for (int i = 0; i < 1000; i++) {
                r++;
            }
            System.out.println(getName() + ":" + r);    // 1000
        }
    }

    public static void main(String[] args) throws InterruptedException {
        MyThread t = new MyThread();
        t.start();

        t.join();
        System.out.println(Thread.currentThread().getName() + ":" + r); // 1000
    }
}